﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace testDecorator
{
    public class Espresso : Beverage
    {
        public Espresso()
        {
            m_strDescription = "Espresso";
        }

        public override double cost()
        {
            return 1.99;
        }
    }

    public class HouseBlend : Beverage
    {
        public HouseBlend()
        {
            m_strDescription = "HouseBlend";
        }

        public override double cost()
        {
            //throw new NotImplementedException();
            return 0.89;
        }
    }

    public class DarkRoast : Beverage
    {
        public DarkRoast()
        {
            m_strDescription = "DarkRoast";
        }

        public override double cost()
        {
            //throw new NotImplementedException();
            return 1.89;
        }
    }


    public class Mocha : CondimentDecorator
    {
        // 要让Mocha能够引用一个Beverage,做法如步骤1 2所示

        // 1 用一个实例变量记录饮料
        Beverage m_objBeverage;

        // 2 想办法让被装饰者（饮料）被记录到实例变量中。
        public Mocha(Beverage beverage)
        { 
            // 这里的做法是：把饮料当作构造器的参数，再由构造器将此饮料记录在实例变量中。
            m_objBeverage = beverage;
        }

        public override string GetDescription()
        {
            //throw new NotImplementedException();
            return m_objBeverage.GetDescription() + ", Mocha";
        }

        // 要计算Mocha饮料的价格。首先把调用委托给被装饰者对象，以计算价钱，然后再加上Mocha的价钱，得到最后的结果。
        public override double cost()
        {
            //throw new NotImplementedException();
            return 0.20 + m_objBeverage.cost();
        }
    }

    public class Whip : CondimentDecorator
    {
        Beverage m_objBeverage;

        public Whip(Beverage beverage)
        {
            m_objBeverage = beverage;
        }

        public override string GetDescription()
        {
            //throw new NotImplementedException();
            return m_objBeverage.GetDescription() + ", Whip";
        }

        public override double cost()
        {
            //throw new NotImplementedException();
            return 0.3 + m_objBeverage.cost();
        }
    }
}
